// const $ = require('jquery')
import $ from 'jquery';

$.ajax({
  type: 'GET',
  url: 'https://api.yizhanketang.cn/api/v1/todos',
  success({data: list}) {
    list.forEach((item, index) => {
      const { content, objectId } = item
      $(`<section>
          <span data-id="${objectId}">${content}</span>
        </section>`).appendTo('main')
    })

    // const { data } = res
    // console.log(data)
    // console.log(list)
    // list.forEach(function (item, index) {
    //   console.log(index)
    //   console.log(item)
    // })
  }
})

// console.log($('main section'))
$('main').on('click', 'section', function () {
  const id = $(this).find('span').data('id')
  location.href = `todo.html?id=${id}`
})

